home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DLLCust_Files / DELTABAR / LIMITDBD.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.9 KB  |  58 lines

  1. // Dynamic link library implementation of NeuroSolutions DeltaBarDelta component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /*****************************/
  6. /* Gradient search procedure */ 
  7.  
  8. __declspec(dllexport) void performDeltaBarDelta(
  9.     DLLData    *instance,        // Pointer to instance data (may be NULL)
  10.     NSFloat *step,            // Pointer to vector of learning rates for each weight
  11.     int    length,                // Length of learning rate vector
  12.     NSFloat    momentum,        // Momentum rate for all weights
  13.     NSFloat    *delta,            // Last weight Update
  14.     NSFloat *gradient,        // Gradient vector from backprop component
  15.     NSFloat *smoothedGradient,    // Smoothed gradient vector
  16.     NSFloat beta,            // Multiplicative constant
  17.     NSFloat kappa,            // Additive constant
  18.     NSFloat zeta             // Smoothing factor
  19.     )
  20. {    
  21.     int i;
  22.     NSFloat stepMax = getFloatParameter(instance, 2, 1); 
  23.  
  24.     for (i=0; i<length; i++) {
  25.         if (smoothedGradient[i]*gradient[i] > 0)
  26.             step[i] += kappa;
  27.         else
  28.             if (smoothedGradient[i]*gradient[i] < 0)
  29.                 step[i] -= beta*step[i]; 
  30.         if (step[i] > stepMax)
  31.             step[i] = stepMax;
  32.         smoothedGradient[i] = (1-zeta)*gradient[i] + zeta*smoothedGradient[i];
  33.     }
  34. }
  35.  
  36. /******************************************/
  37. /* Management of instance data (OPTIONAL) */
  38. __declspec(dllexport) DLLData *allocDeltaBarDelta(
  39.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  40.     int    length,        // Length of the weight vector
  41.     BOOL    individual    // Indicates whether their is one learning rate for all weights (FALSE),
  42.                 // or each weight has its own learning rate
  43.     )
  44. {
  45.     DLLData *instance = allocDLLInstance(oldInstance);
  46.     setParameterName(instance, 2, 1, "Max Step", TRUE);
  47.     setFloatParameter(instance, 2, 1, 0.1f, FALSE);
  48.     if (getFloatParameter(instance, 2, 1) < 0)
  49.         setFloatParameter(instance, 2, 1, 0.0f, TRUE);
  50.     return instance;
  51. }
  52.  
  53. __declspec(dllexport) void freeDeltaBarDelta(DLLData *instance)
  54. {
  55.     freeDLLInstance(instance);
  56. }
  57.  
  58.